package org.xilin

class Course {
    String          name
    String          desc1
    String          desc2
    String          grade
    Integer         capacity    = 20
    Integer         regCapacity = 0
    Integer         price       = 0
    Boolean         status      = true
    String          startTime   = "13:00"
    String          endTime     = "13:50"
    Teacher         teacher
    Book            book
    RoomSchedule    classRoom
    Semester        semester
    User            updatedBy
    Date            dateCreated, lastUpdated
    String          category

    static String[] categories = ['CHINESE', 'MATH', 'ACTIVITY']
  
    static transients = ['categories']
    static hasMany = [classes:TheClass]
    //static belongsTo = Student

    
    static constraints = {
        name        (size:2..60, unique:true, blank:false)
        desc1       (nullable:true)
        desc2       (nullable:true)
        grade       (nullable:true)
        capacity    (min:1)
        regCapacity (min:0)
        price       (min:0)
        startTime   (size:5..5)
        endTime     (size:5..5)
        teacher     (nullable:true)
        book        (nullable:true)
        classRoom   (nullable:true)
        semester    (nullable:true)
        updatedBy   (nullable:true)
        category    (nullable:true)
    }

    static mapping = {
        columns {
            name index:'course_name_idx, Name_Create_Date_Idx'
        }
        version false
        cache true
        book cache:true
        classes lazy:false
    }

    String toString() {
        name
    }
}
